package com.sky.config;


import cn.dev33.satoken.stp.StpInterface;
import cn.dev33.satoken.stp.StpUtil;
import com.sky.context.BaseContext;
import com.sky.service.AdminUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义权限加载接口实现类
 *
 * @author majun
 * @package com.sky.config
 * @date 2024/11/29 21:54
 */
@Slf4j
@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private AdminUserService adminUserService;

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {

        String adminId = StpUtil.getLoginId().toString();

        return adminUserService.getPermissionsByAdminId(adminId);
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {

        String adminId = StpUtil.getLoginId().toString();

        return adminUserService.getAdminRoles(adminId);

    }

}
